---
import { englishPages } from '~/content';
import { isCmsEntry } from '~/content.config';
import { getLanguageFromURL } from '~/util/path-utils';
import CardsNav from './NavGrid/CardsNav.astro';

const lang = getLanguageFromURL(Astro.url.pathname);
const enPages = englishPages.filter(isCmsEntry);

const links = enPages
	// Sort alphabetically.
	.sort((a, b) => (a.id > b.id ? 1 : -1))
	.map((page) => {
		const { logo, sidebar } = page.data;
		if (!sidebar.label) throw new Error('CMS guides must always include a sidebar label.');
		const pageUrl = '/' + page.id.replace('en/', `${lang}/`) + '/';
		return { title: sidebar.label, href: pageUrl, logo };
	});
---

<section>
	<CardsNav minimal links={links} />
</section>
